﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KendoMvcUI.Core;
using KendoMvcUI.Common;
using System.Web.Mvc;

namespace KendoMvcUI.UI
{
    public class MultiSelect:KendoUIBase
    {
        public MultiSelect(KendoUIControlSettings settings,ViewContext context,IViewDataContainer viewDataContainer)
            :base(settings,context,viewDataContainer)
        { }
        public override string RenderHtml()
        {
            return "<select id=\"{0}\"></select>".Formator(Settings.Id);
        }
    }
    public class MultiSelectSettings : KendoBindingBase
    {
        public MultiSelectSettings()
            : base("kendoMultiSelect")
        { }
        [PropertySetting(IsIngoreForJavaScript=true)]
        public Action<AnimationSettings> Animation { get; set; }
        public bool? AutoBind { get; set; }
        public bool? AutoClose { get; set; }
        /// <summary>
        /// Important When dataTextField is defined, thedataValueField option also should be set.
        /// </summary>
        public string DataTextField { get; set; }
        public string DataValueField { get; set; }
        /// <summary>
        /// Specifies the delay in milliseconds after which the MultiSelect will start filtering dataSource.
        /// default:200
        /// </summary>
        public int? Delay { get; set; }
        /// <summary>
        /// If set to false the widget will be disabled and will not allow user input.
        /// default:true
        /// </summary>
        public bool? Enable { get; set; }
        /// <summary>
        /// The filtering method used to determine the suggestions for the current value. 
        /// Filtration is turned of by default. The supported filter values are startswith, endswith and contains.
        /// </summary>
        public string Filter { get; set; }
        /// <summary>
        /// If set to true the first suggestion will be automatically highlighted.
        /// default:true
        /// </summary>
        public bool? HighlightFirst { get; set; }
        /// <summary>
        /// If set to false case-sensitive search will be performed to find suggestions. 
        /// default:true
        /// </summary>
        public bool? IgnoreCase { get; set; }
        /// <summary>
        /// The minimum number of characters the user must type before a search is performed
        /// </summary>
        public int? MinLength { get; set; }
        /// <summary>
        /// Defines the limit of the selected items. If set to null widget will not limit number of the selected items.
        /// default:null
        /// </summary>
        public int? maxSelectedItems { get; set; }
        public string Placeholder { get; set; }
        /// <summary>
        /// Specifies a static HTML content, which will be rendered as a header of the popup element.
        /// Important Widget does not pass a model data to the header template. Use this option only with static HTML.
        /// </summary>
        public string HeaderTemplate { get; set; }
        /// <summary>
        /// <script id="itemTemplate" type="text/x-kendo-template">
        ///<span>
        /// <img src="/img/#: id #.png" alt="#: name #" />
        /// #: name #
        ///</span>
        ///kendo.template($("#itemTemplate").html())
        ///</script>
        /// </summary>
        public string ItemTemplate { get; set; }
        public string TagTemplate { get; set; }
        /// <summary>
        /// Important: Define a list of data items if widget is not initially bound
        /// </summary>
        public List<string> Value { get; set; }
        /// <summary>
        /// Specifies the value binding behavior for the widget. 
        /// If set to true, the View-Model field will be updated with the selected item value field. 
        /// If set to false, the View-Model field will be updated with the selected item.
        /// default:false
        /// </summary>
        public bool? valuePrimitive { get; set; }

        #region 事件
        public string On_Change { get; set; }
        public string On_Close { get; set; }
        public string On_DataBound { get; set; }
        public string On_Filtering { get; set; }
        public string On_Open { get; set; }
        public string On_Select { get; set; }
        #endregion

        public override string ToJsSettings()
        {
            var js = base.ToJsSettings();
            if (!js.EndsWith(","))
                js += ",";
            if (Animation != null)
            {
                AnimationSettings animation = new AnimationSettings();
                Animation(animation);
                js += animation.ToString() + ",";
            }
            return js.TrimEnd(',');
        }
    }
}
